home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1994 November / Cd Ware (Nro. 2) - Epimundo.iso / DOS / PG / OOLIFE.ZIP / CA.H < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-09  |  1.9 KB  |  77 lines

  1. typedef int BOOL;
  2. #define TRUE 1
  3. #define FALSE 0
  4.  
  5. class CLife;
  6. class CNode
  7. {
  8. private:
  9.     CNode *prev, *next;
  10.     CLife *life;
  11. protected:
  12. public:
  13.     CNode() {prev=0;next=0;life=0;}
  14.     CNode* getPrev() {return prev;}
  15.     CNode* getNext() {return next;}
  16.     CLife* getLife() {return life;}
  17.     void setPrev(CNode *set) {prev=set;}
  18.     void setNext(CNode *set) {next=set;}
  19.     void setLife(CLife *set) {life=set;}
  20. };
  21.  
  22.  
  23. class CLifeList        //Implements a double linked non-circular list
  24. {
  25. private:
  26.     CNode *top;
  27.     CNode *current;
  28.     CNode *bottom;
  29.     long  cells;
  30. protected:
  31. public:
  32.     CLifeList() {cells=0;}
  33.     CLife *getLife() {return current->getLife();}
  34.     void skip() {current = current->getNext();}
  35.     void goTop() {current=top;}
  36.     short addLife(CLife *toAdd);
  37.     short countLive();        //Used for cycling and status
  38.     void dirty();            //Mark all the cells in the container as dirty
  39.     void associateCells(); //Update the cells neighbors
  40.     void cycle();            //cycle all the cells in the list
  41.     void update();            //update all the cells in the list
  42.  
  43. };
  44.  
  45. class CGraphic
  46. {
  47. // This class implements the graphics that will be displayed
  48. private:
  49.     short x, y;    //A better implementation would have a location class
  50. protected:
  51. public:
  52.     void draw(BOOL on);    //draw a graphic of the life.
  53.     CGraphic(short inx, short iny) { x=inx; y=iny; }
  54. };
  55.  
  56. class CLife
  57. {
  58. private:
  59.     BOOL lifeState;
  60.     BOOL newState;
  61.     BOOL newDirty;
  62.     BOOL dirty;
  63.     CLifeList neighbors;
  64.     CGraphic  *graphic;
  65. protected:
  66. public:
  67.     CLife() {graphic=0;}
  68.     void setLife(BOOL alive) {newState = alive;}
  69.     BOOL isLive() {return lifeState;}
  70.     void cycle();    //Checks the status of neighbors to determine life prospects
  71.     void update() {lifeState=newState; dirty=newDirty; newDirty=FALSE;}
  72.     short addNeighbor(CLife *add) {return neighbors.addLife(add);}
  73.     void setDirty() {newDirty = TRUE;}
  74.     void setGraphic( CGraphic *newGraphic ) {graphic=newGraphic;}
  75. };
  76.  
  77.